package com.cyandpos.pad.report.reportView;

import android.content.Context;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;

import com.cyandpos.pad.R;
import com.cyandpos.pad.posdata.ReportPay;
import com.cyandpos.pad.report.adapter.ListViewCashAdapter;
import com.cyandpos.pad.utils.MoneyUtils;

import java.util.ArrayList;
import java.util.List;

/**
 *
 * 班报卡
 */

public class CashReportView extends FrameLayout {
    View main;
    //List<Payment> paymentList = new ArrayList<>();
    List<ReportPay> paymentList=new ArrayList<>();
    ListView listView;
    TextView textView2;
    ListViewCashAdapter listViewAdapter;

    /**
     * 交易基本信息的控件
     */
    private TextView tv_report_shop_assistant, tv_report_departmentCode, tv_report_trade_No, tv_report_trade_money;
    private TextView tv_report_return_goods_No, tv_report_return_goods_money;
    /**
     * 是否隐藏显示行
     */
    private LinearLayout ll_report_show_or_not;

    public CashReportView(Context context) {

        super(context);
        main = inflate(context, R.layout.report_pager, null);
//        main.setVisibility(INVISIBLE);
        listView = (ListView) main.findViewById(R.id.lv_cash_report);
        textView2 = (TextView) main.findViewById(R.id.tv_show_report_count);
        textView2.setText("溢余");
        listViewAdapter = new ListViewCashAdapter(paymentList, context);
        listView.setAdapter(listViewAdapter);
        tv_report_shop_assistant = (TextView) main.findViewById(R.id.tv_report_shop_assistant);
        tv_report_departmentCode = (TextView) main.findViewById(R.id.tv_report_departmentCode);
        tv_report_trade_No = (TextView) main.findViewById(R.id.tv_report_trade_No);
        tv_report_trade_money = (TextView) main.findViewById(R.id.tv_report_trade_money);
        tv_report_return_goods_No = (TextView) main.findViewById(R.id.tv_report_return_goods_No);
        tv_report_return_goods_money = (TextView) main.findViewById(R.id.tv_report_return_goods_money);
        ll_report_show_or_not = (LinearLayout) main.findViewById(R.id.ll_report_show_or_not);
        addView(main);
    }


    /**
     * LISTVIEW的 notifydatachange
     *
     * @param paymentList
     */
    public void dateChanged(List<ReportPay> paymentList) {
        this.paymentList.clear();
        this.paymentList.addAll(paymentList);
        listViewAdapter.notifyDataSetChanged();

    }


    /**
     * 设置显示营业员姓名
     *
     * @param name
     */
    public void setShopAssistantName(String name) {
        if (name.isEmpty() || name == null) {
            return;
        } else {
            tv_report_shop_assistant.setText(name);
        }
    }


    /**
     * 设置显示总销售总额
     *
     * @param totalMoney
     */
    public void setTotalTradeMoney(int totalMoney) {
        tv_report_trade_money.setText(MoneyUtils.getMoneyStr(totalMoney));
    }

    /**
     * 设置显示总退货次数
     *
     * @param totalBackNo
     */
    public void setTotalBackNo(int totalBackNo) {
        tv_report_return_goods_No.setText(String.valueOf(totalBackNo));
    }

    /**
     * 设置显示总退货金额
     *
     * @param totalBackMoney
     */
    public void setTotalBackMoney(int totalBackMoney) {
        tv_report_return_goods_money.setText(MoneyUtils.getMoneyStr(totalBackMoney));
    }

    /**
     * 设置显示总销售次数
     *
     * @param totalTradeNo
     */
    public void setTotalTradeNo(int totalTradeNo) {
        tv_report_trade_No.setText(String.valueOf(totalTradeNo));
    }

    /**
     * 设置显示部门代码
     *
     * @param code
     */
    public void setDepartmentCode(String code) {
        if (code.isEmpty() || code == null) {
            return;
        } else {
            tv_report_departmentCode.setText(code);
        }
    }
}
